//
//  JPBottomSafeBaseView.m
//  MaterialMallDemo
//
//  Created by mac on 2018/5/11.
//  Copyright © 2018年 zhuangdian. All rights reserved.
//

#import "JPBottomSafeBaseView.h"


@interface JPBottomSafeBaseView()

/**
 底部安全高度（适配iphoneX）
 */
@property (nonatomic ,assign) CGFloat bottomSafeHeight;

/*!
 顶部线条
 */
@property (nonatomic ,strong) UIView * topLine;

/*!
 底部线条
 */
@property (nonatomic ,strong) UIView * bottomLine;

@end

@implementation JPBottomSafeBaseView

-(void)setTopLineColor:(UIColor *)topLineColor{
    _topLineColor = topLineColor;
    self.topLine.backgroundColor = topLineColor;
}
-(void)setBottomLineColor:(UIColor *)bottomLineColor{
    _bottomLineColor = bottomLineColor;
    self.bottomLine.backgroundColor = bottomLineColor;
}
-(CGFloat)jp_height{
    [self layoutIfNeeded];
    return CGRectGetMaxY(self.contentView.frame) + self.bottomSafeHeight;
}


-(CGFloat)bottomSafeHeight{
    
    BOOL isIphoneX = ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO);
    
    return isIphoneX ? 34 : 0;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self jp_createContentView];
        [self jp_setupContentView];
    }
    return self;
}
 
-(void)jp_createContentView{
    
    static CGFloat kLineHeight = 0.8;

    UIColor * lineColor = [UIColor colorWithRed:238.0 / 255.0 green:238.0 / 255.0 blue:238.0 / 255.0 alpha:1];

    //展示内容视图
    self.contentView = [UIView new];
    [self addSubview:self.contentView];
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
        make.bottom.mas_equalTo(-self.bottomSafeHeight);
    }];
 
    //视图顶部分割线
    self.topLine = [UIView new];
    self.topLine.backgroundColor = lineColor;
    [self.contentView addSubview:self.topLine];
    [self.topLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
        make.height.mas_equalTo(kLineHeight);
    }];
    //视图底部分割线
    self.bottomLine = [UIView new];
    self.bottomLine.backgroundColor = lineColor;
    [self.contentView addSubview:self.bottomLine];
    [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.mas_equalTo(0);
        make.height.mas_equalTo(kLineHeight);
    }];
}
-(void)jp_setupContentView{}



@end
